typedef enum _EventType{
    None = 0,
    MouseEnter = 1,
    MouseLeave = 2,
    MouseMove = 3,
    MouseDown = 4,
    MouseUp = 5,
    LeftMouseDoubleClick = 6,
    RightMouseDown = 7,
    RightMouseUp = 8,
    MouseWheel = 9,
    KeyUp = 10,
    KeyDown = 11
} EventType;

struct Event 
{
    EventType type;
    UInt32 timestamp;
    SInt16 x;
    SInt16 y;
    CGKeyCode keyCode;
    //BOOL mouseDown;
};
typedef struct Event Event;

static inline Event
EventParse(const UInt8 *data)
{
    Event result;
    //UInt32 timestamp = 0;
    UInt8 position = 0;
    
    while(position < sizeof(int))
    {
        result.timestamp += (UInt32)data[position] << (position * 8);
        position++;
    }
    
    EventType eventType = data[position++];
    SInt16 xOrKeyCode = data[position++] + (data[position++] << 8);
    SInt16 y = data[position++] + (data[position++] << 8);
    
    
    result.type = eventType;

    if(eventType == KeyUp || eventType == KeyDown)
    {
        result.keyCode = xOrKeyCode;
    }
    else
    {
        result.x = xOrKeyCode;
    }
    result.y = y;
    return result;
}